package com.dz.scrm.app.adpter;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dz.scrm.R;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Description: 拨打电话键盘
 * @Author: 黄海
 * @CreateDate: 2021-4-23 9:56
 * @UpdateUser: 黄海
 * @UpdateDate: 2021-4-23 9:56
 * @UpdateRemark: 更新说明
 */
public class KeyBoardAdpter extends RecyclerView.Adapter<KeyBoardAdpter.ViewHolder>{

    private Context context;
    private List<String> data;
    private itemOnClickListener listener;
    public KeyBoardAdpter(Context context, List<String> data, itemOnClickListener listener) {
        this.context = context;
        this.data = data;
        this.listener = listener;
    }

    @NonNull
    @Override
    public KeyBoardAdpter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_keyborad_recycle_layout,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvNum.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); //加粗
        if (data != null && data.get(position) != null){
            if (position < 9){
                holder.tvNum.setText((position+1)+"");
                holder.tvChar.setText(data.get(position));
                holder.imgPoint.setVisibility(View.GONE);
            }else if (position == 9){
                holder.tvNum.setVisibility(View.GONE);
                holder.tvChar.setVisibility(View.GONE);
                holder.imgPoint.setVisibility(View.VISIBLE);
                holder.imgPoint.setImageResource(R.mipmap.icon_start);
            }else if (position == 10){
                holder.tvNum.setText("0");
                holder.tvChar.setText("");
                holder.tvNum.setVisibility(View.VISIBLE);
                holder.tvChar.setVisibility(View.VISIBLE);
                holder.imgPoint.setVisibility(View.GONE);
            }else if (position == 11){
                holder.tvNum.setVisibility(View.GONE);
                holder.tvChar.setVisibility(View.GONE);
                holder.imgPoint.setVisibility(View.VISIBLE);
                holder.imgPoint.setImageResource(R.mipmap.icon_jing);
            }

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null){
                        listener.onClick(position);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return 12;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tvNum,tvChar;
        private ImageView imgPoint;

        public ViewHolder(View itemView) {
            super(itemView);
            tvNum = itemView.findViewById(R.id.tvNum);
            tvChar = itemView.findViewById(R.id.tvChar);
            imgPoint = itemView.findViewById(R.id.imgPoint);
        }
    }

    public interface itemOnClickListener{
        void onClick(int position);
    }
}
